﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace teach
{
    public class Espagnol : Question, ITextQuestion
    {
        public string QuestionText { get; set; }
        public bool SpanishMode { get; set; }

        public Espagnol()
        {
            m_message = "Traduction";
        }

        public override object Answer
        {
            get
            {
                if (SpanishMode)
                {
                    return Properties["spanish"];
                }
                else
                {
                    return Properties["french"];
                }
            }
        }

        public override bool CheckAnswer(object userAnswer)
        {
            bool result = (userAnswer.ToString().Trim().ToLower() == Answer.ToString().ToLower());
            if (result == false)
            {
                if (SpanishMode && Properties.ContainsKey("spanish2"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["spanish2"].ToString().ToLower());
                }
                else if (SpanishMode && Properties.ContainsKey("spanish3"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["spanish3"].ToString().ToLower());
                }
                else if (SpanishMode && Properties.ContainsKey("spanish4"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["spanish4"].ToString().ToLower());
                }
                else if (SpanishMode && Properties.ContainsKey("spanish5"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["spanish5"].ToString().ToLower());
                }
                else if (SpanishMode && Properties.ContainsKey("spanish6"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["spanish6"].ToString().ToLower());
                }
                else if (!SpanishMode && Properties.ContainsKey("french2"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["french2"].ToString().ToLower());
                }
                else if (!SpanishMode && Properties.ContainsKey("french3"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["french3"].ToString().ToLower());
                }
                else if (!SpanishMode && Properties.ContainsKey("french4"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["french4"].ToString().ToLower());
                }
                else if (!SpanishMode && Properties.ContainsKey("french5"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["french5"].ToString().ToLower());
                }
                else if (!SpanishMode && Properties.ContainsKey("french6"))
                {
                    result = (userAnswer.ToString().Trim().ToLower() == Properties["french6"].ToString().ToLower());
                }
            }
            return result;
        }

        public override void GenerateValues(Preference pref)
        {
            this.Timeout = pref.Timeout * 1000;
            Random rnd = new Random();
            if (rnd.Next(100) > 50)
            {
                SpanishMode = true;
                m_message = "Hablamos español!";
                QuestionText = Properties["french"];
            }
            else
            {
                SpanishMode = false;
                m_message = "En français?";
                QuestionText = Properties["spanish"];
            }
        }
    }
}
